// 图片状态过滤器
let is_enableFilter = (val) => {
    if (val === 0) {
        return "已经上架"
    } else {
        return "已经下架"
    }
}
let is_enableBanner = (val) => {
    if (val === 0) {
        return "开启状态"
    } else {
        return "关闭状态"
    }
}

let topicStatusFilter = (val) => {
    if (val === 0) {
        return "开启"
    } else {
        return "关闭"
    }
}


let fomatFloat = (num, n) => {
    // num为传入的值，n为保留的小数位
    var f = parseFloat(num);
    if (isNaN(f)) {
        return false;
    }
    f = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); // n 幂   
    var s = f.toString();
    var rs = s.indexOf('.');
    //判定如果是整数，增加小数点再补0
    if (rs < 0) {
        rs = s.length;
        s += '.';
    }
    while (s.length <= rs + n) {
        s += '0';
    }
    return s;
}

// 计算已注册天数
let CalRegisterDay=function(v){
    var a = new Date();
    var b = new Date(v);
    var diff = a - b;
    var days = diff / 1000 / 60 / 60 /24;
    days = Math.floor(days);
    return days
}



let fillImgShot = (v) => {
    return `/api/base/get-shot?img=${v}`
}

// let fillUpImgShot = (v) => {
//     return `${process.env.VUE_APP_BASE_API.replace("/api/wbms","")}/api/base/get_image?img=${v}`
// }

let getStaticImg = (v) => {
    return `/images/${v}`
}
let getStaticIcon = (v) => {
    return `/icons/${v}`
}
// 填充上传的图片
let fillUpImgShot = (v) => {
    return `/api/base/get_image?img=${v}`
}

let linkTypeFilter = (v) => {
    if (v === 1) {
        return "分类"
    } else if (v === 2) {
        return "标签"
    } else if (v === 3) {
        return "专题"
    } else if (v === 4) {
        return "链接"
    }
}
let linkTypeEName = (v) => {
    if (v === 1) {
        return "Category"
    } else if (v === 2) {
        return "Tag"
    } else if (v === 3) {
        return "Topic"
    } else if (v === 4) {
        return "Link"
    }
}

let getImgSuffix = (v) => {
    if( v == undefined ) return '';
    var FileExt = v.replace(/.+\./, "").toUpperCase();
    return FileExt
}


// 根据分类id获取分类名称
let categoryFilter=(v,list)=>{
    for(var o of list){
        if(o.id==v){
            return o.name
        }
    }
}


export {
    is_enableFilter,
    is_enableBanner,
    topicStatusFilter,
    fomatFloat,
    fillImgShot,
    linkTypeFilter,
    getStaticImg,
    getImgSuffix,
    linkTypeEName,
    categoryFilter,
    fillUpImgShot,
    CalRegisterDay,
    getStaticIcon
}